package cis350.pcr;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;

import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;

import com.loopj.android.http.AsyncHttpResponseHandler;

import cis350.pcr.activities.LoginActivity;
//import edu.upenn.isc.fastPdfServiceClient.api.FpsPennGroupsHasMember;
import android.app.ProgressDialog;
import android.content.Context;
import android.os.AsyncTask;
import android.util.Log;

//import edu.upenn.isc.fastPdfServiceClient.api.*;

public class AuthenticateTask extends AsyncTask<Void, Void, Boolean> {
	String loginString;

	public AuthenticateTask(String name) {
		loginString = name;
	}

	@Override
	protected Boolean doInBackground(Void... params) {
		try {
			HttpClient httpclient = new DefaultHttpClient();
			HttpResponse response = httpclient.execute(new HttpGet("http://www.penncoursereview.com/androidapp/auth?serial=" + loginString));
			InputStream is = response.getEntity().getContent();

			StringBuilder fileContent = new StringBuilder();
			char character = 0;
			while ((character = (char) is.read()) != 65535) {
				fileContent.append(character);
			}
			String pennKey = fileContent.toString().trim();
			Log.d("Pennkey", pennKey);
			return true;
		} catch (IOException e) {
			return false;
		}

	}

}